<?php
namespace Admin\Controller;

class MarryController extends AdminController{

	public function index(){
        $list   = $this->lists('marry');
        $this->assign('_list', $list);
        $this->meta_title = '结婚吧';
		$this->display();
	}
	public function marryinfo(){
		$id = I("id",0);
		$when = '(case sex when 1 then "男" when 2 then "女" end) as sexname,';
		$when.= '(case married when 1 then "未婚" when 2 then "离异" when 3 then "丧偶" end) as marriedname,';
		$when.= '(case zo_married when 0 then "不限" when 1 then "未婚" when 2 then "离异" when 3 then "丧偶" end) as zo_marriedname,';
		$when.= '(case zo_room when 0 then "不限" when 1 then "有房" when 2 then "没有" end) as zo_roomname,';
		$when.= '(case zo_car when 0 then "不限" when 1 then "有房" when 2 then "没有" end) as zo_carname';
		$info = M('marry')->field("*".",".$when)->find($id);
		$litpics = explode(',',$info['litpic']);
		foreach ($litpics as $key=>$val) {
            $info['litpics'] = M('picture')->where('id='.$val)->getField('path');
        }
        $roomlitpic = explode(',',$info['roomlitpic']);
        foreach ($roomlitpic as $key=>$val) {
            $info['roomlitpic'] = M('picture')->where('id='.$val)->getField('path');
        }
        $carlitpic = explode(',',$info['carlitpic']);
        foreach ($carlitpic as $key=>$val) {
            $info['carlitpic'] = M('picture')->where('id='.$val)->getField('path');
        }
        $ident = explode(',',$info['ident']);
        foreach ($ident as $key=>$val) {
            $info['ident'] = M('picture')->where('id='.$val)->getField('path');
        }
		$this->assign('info',$info);
		$this->display();
	}
	public function dispose(){
		$id = I('id',0);
		$type = I('type');
		if (!in_array($type, array(1,2))) {
			$this->error("参数错误");
		}
		$data = array(
			"id" => $id,
			"type"	=> $type
		);
		if (M('marry')->save($data)) {
			$this->success("操作成功");
		}else{
			$this->error("操作失败");
		}
	}
}